package cn.xz.kjg.dialog

import android.view.Gravity
import androidx.cardview.widget.CardView
import cn.xz.kjg.R
import cn.xz.kjg.base.BaseDialogRxFragment

/**
 * 强制删除缓存提示弹窗
 * */
class ClearCacheDialog: BaseDialogRxFragment() {

    private var mClickListener: OnClickListener? = null

    private var cvYes: CardView? = null
    private var cvNo: CardView? = null

    companion object {
        fun newInstance(
            clickListener: OnClickListener
        ): ClearCacheDialog {
            val dialog = ClearCacheDialog()
            dialog.mClickListener = clickListener
            return dialog
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.dialog_clear_cahce
    }

    override fun configDialog() {
        this.setDialogSize(gravity = Gravity.CENTER,width = 300)
    }

    override fun initViews() {

        dialog?.let {
            cvYes = it.findViewById(R.id.cv_yes)
            cvNo = it.findViewById(R.id.cv_no)
        }

        //点击外部不隐藏
        dialog?.setCancelable(false)
        dialog?.setCanceledOnTouchOutside(false)
        //点击事件
        initEvent()
    }


    private fun initEvent(){
        cvYes?.setOnClickListener {
            mClickListener?.onYes()
            dismiss()
        }
        cvNo?.setOnClickListener {
            mClickListener?.onNo()
            dismiss()
        }
    }


    interface OnClickListener {
        fun onYes()
        fun onNo()
    }

}